//集合set运用  
#include <iostream> 
#include <set>
#include <string>
using namespace std;

//1.令Student支持opreator<
class Student
{
public:
    int ID;
    string name;
    float score;

    Student(int id= 0,string n = "null",float s = 0.0 )
        :ID(id),name(n),score(s) {}
    
    void showInfo() const
    {
        cout << "学号：" << ID << ";";
        cout << "姓名：" << name << ";";
        cout << "分数；" << score << endl; 
    }

    // //由分数大小排序
    // bool operator<(const Student &s) const
    // {
    //     return score < s.score;
    //     //return ID < s.ID; //按照Id号排序
    // }
};

class cmp
{
public:
    bool operator()(const Student& s1,const Student& s2) const
    {
        return s1.score < s2.score;
    } 
};

int main(int argc, char const *argv[])
{
    //2.使用自定义的比较器来组织元素
    set<Student,cmp> s;

    s.insert(Student(1,"张三",90.0));
    s.insert(Student(2,"李四",78.0));
    s.insert(Student(3,"王五",86.0));
    
    for(auto it = s.begin();it != s.end();it++)
    {
        it->showInfo();

    }

    return 0;
}
